#!/usr/bin/perl
use utf8;
use strict;
use Data::Dumper;

$Data::Dumper::Useqq = 1;{
 no warnings 'redefine';
 sub Data::Dumper::qquote {
   my $s = shift;
   return "'$s'";
 }
}

open (FILE, "out.txt") or die "Sorry, but i can't open 'out.txt'";
binmode(FILE, ":encoding(utf-8)");
binmode(STDOUT, ":encoding(utf-8)");
binmode(STDERR, ":encoding(utf-8)");
open (FIL, '>>male.txt') or die;
binmode(FIL, ":encoding(utf-8)");
open (F, '>>female.txt') or die;
binmode(F, ":encoding(utf-8)");


my @s=<FILE>;
my %m;
my %f;
my $i;

foreach my $line (@s){
	if ($i = index($line, "Male") != -1)
	{
		$i = index ($line, "= ");
		$a = substr ($line, $i+2,length($line)-$i-3);
		$m{lc($a)} += 1;
		
	}
	if ($i = index($line, "Female") != -1)
        {
                $i = index ($line, "= ");
                $a = substr ($line, $i+2,length($line)-$i-3);
                $f{lc($a)} += 1;
                
        }

}
my @sort = sort {$m{$b} <=> $m{$a}} keys %m;
my $el;
foreach $el (@sort){
	if ($m{$el} != 1) {print FIL "$el\n";} 
	print $el, " => ", $m{$el}, "\n";
}
my @sort = sort {$f{$b} <=> $f{$a}} keys %f;
my $el;
foreach $el (@sort){
        if ($f{$el} != 1) {print F "$el\n";} 
        print $el, " => ", $f{$el}, "\n";
}



#print Dumper(\%persn);

